home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / s_to_z / tpasswrd / pwd.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-15  |  3KB  |  116 lines

  1. unit Pwd;
  2.  
  3. { Password demo created by  }
  4. { Total Data Concept AS.    }
  5.  
  6. { This is a example for the }
  7. { TPassword and TPasswordBox}
  8. { components.      }
  9.  
  10. { This code should be self- }
  11. { documenting. If you have  }
  12. { any questions please send }
  13. { us a note via CompuServe. }
  14. { Read the readme.wri file  }
  15. { for more information.     }
  16.  
  17. interface
  18.  
  19. uses
  20.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  21.   Forms, Dialogs, StdCtrls, Password, Grids, DBGrids, DB, DBTables,
  22.   Pwdbox;
  23.  
  24. type
  25.   TForm1 = class(TForm)
  26.     DataSource1: TDataSource;
  27.     Table1: TTable;
  28.     DBGrid1: TDBGrid;
  29.     Password1: TPassword;
  30.     Button1: TButton;
  31.     Button2: TButton;
  32.     Button3: TButton;
  33.     Button4: TButton;
  34.     PasswordBox1: TPasswordBox;
  35.     procedure Button4Click(Sender: TObject);
  36.     procedure Button3Click(Sender: TObject);
  37.     procedure Button2Click(Sender: TObject);
  38.     procedure Button1Click(Sender: TObject);
  39.     procedure Password1AfterSetPassword(Sender: TObject);
  40.     procedure FormCreate(Sender: TObject);
  41.     procedure Password1AfterClearPassword(Sender: TObject);
  42.     procedure PasswordBox1NotPassed(Sender: TObject);
  43.   private
  44.     { Private declarations }
  45.  
  46.   public
  47.     { Public declarations }
  48.   end;
  49.  
  50. var
  51.   Form1: TForm1;
  52.  
  53. implementation
  54.  
  55. {$R *.DFM}
  56.  
  57. procedure TForm1.Button4Click(Sender: TObject);
  58. begin
  59.      Table1.Close;
  60. end;
  61.  
  62. procedure TForm1.Button3Click(Sender: TObject);
  63. begin
  64.      try
  65.         Table1.Open;
  66.      except
  67.      end;
  68. end;
  69.  
  70. procedure TForm1.Button2Click(Sender: TObject);
  71. begin
  72.      { Clear the password and remove session passwords }
  73.      Password1.ClearPassword;
  74. end;
  75.  
  76. procedure TForm1.Button1Click(Sender: TObject);
  77. var
  78.    PwdString: string;
  79. begin
  80.      { Query and set password... }
  81.      { InputQuery does not mask any inputcharacters, but
  82.        is used for demonstration purposes only.. } 
  83.      PwdString := 'MyPassword';
  84.      if InputQuery('TPassword Demo','Enter Password', PwdString) then
  85.         Password1.SetPassword(PwdString);
  86. end;
  87.  
  88. procedure TForm1.Password1AfterSetPassword(Sender: TObject);
  89. begin
  90.      { Remove this line to keep the session password }
  91.      Session.RemoveAllPasswords;
  92.  
  93.      { Need to reset the password counter }
  94.      PasswordBox1.Reset;
  95. end;
  96.  
  97. procedure TForm1.Password1AfterClearPassword(Sender: TObject);
  98. begin
  99.      PasswordBox1.Reset;
  100. end;
  101.  
  102. procedure TForm1.FormCreate(Sender: TObject);
  103. begin
  104.      try
  105.         Table1.Open;
  106.      except
  107.      end;
  108. end;
  109.  
  110. procedure TForm1.PasswordBox1NotPassed(Sender: TObject);
  111. begin
  112.      MessageDlg('No no no ... wrong password...', mtInformation, [mbOk], 0);
  113. end;
  114.  
  115. end.
  116.